package com.example.zhaojianxu.signin.englishgame.start

import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.ViewGroup
import com.example.zhaojianxu.signin.R
import com.example.zhaojianxu.signin.englishgame.http.EGStartEntity

/**
 * create by @zhaojianxu on 2019/2/26
 */
class StartAdapter: RecyclerView.Adapter<StartViewHolder>(){

    var mList = mutableListOf<EGStartEntity>()

    fun bindData(list: MutableList<EGStartEntity>){
        mList.clear()
        mList.addAll(list)
        notifyDataSetChanged()
    }


    override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): StartViewHolder {
        val view = LayoutInflater.from(parent?.context).inflate(R.layout.item_start_view,parent,false).apply {
            this.layoutParams?.let {
                it.height = (parent?.height?.div(mList.size)!!)
            }
        }
        return StartViewHolder(view)
    }

    override fun getItemCount(): Int {
        return mList.size
    }

    override fun onBindViewHolder(holder: StartViewHolder?, position: Int) {
        holder?.bindData(mList[position])
    }

}